﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AnyGrid.Renderers;

namespace AnyGrid.Tests
{
    [TestClass]
    public class JavaScriptElementTests
    {
        [TestMethod]
        public void Create_works_for_array()
        {
            int[] input = new[] { 1, 2, 3 };

            JavaScriptElement result = JavaScriptElement.Create(input);

            Assert.IsInstanceOfType(result, typeof(JavaScriptArray));
            Assert.AreEqual("[1,2,3]", result.ToString());
        }

        [TestMethod]
        public void Create_works_for_int()
        {
            int input = 1;

            JavaScriptElement result = JavaScriptElement.Create(input);

            Assert.IsInstanceOfType(result, typeof(JavaScriptLiteral));
            Assert.AreEqual(input.ToString(), result.ToString());
        }

        [TestMethod]
        public void Create_works_for_JavaScriptElement()
        {
            JavaScriptLiteral input = new JavaScriptLiteral(123);

            JavaScriptElement result = JavaScriptElement.Create(input);

            Assert.AreEqual(input, result);
        }

        [TestMethod]
        public void Create_works_for_long()
        {
            long input = -1239834729323432;

            JavaScriptElement result = JavaScriptElement.Create(input);

            Assert.IsInstanceOfType(result, typeof(JavaScriptLiteral));
            Assert.AreEqual(input.ToString(), result.ToString());
        }

        [TestMethod]
        public void Create_works_for_object()
        {
            var input = new
            {
                A = "foo",
                B = 2,
                C = new
                {
                    Foo = 1,
                    Bar = "bar"
                }
            };

            JavaScriptElement result = JavaScriptElement.Create(input);

            Assert.IsInstanceOfType(result, typeof(JavaScriptObject));
        }

        [TestMethod]
        public void Create_works_for_string()
        {
            string input = "alkdslajads;sdakldaskads;l";

            JavaScriptElement result = JavaScriptElement.Create(input);

            Assert.IsInstanceOfType(result, typeof(JavaScriptLiteral));
            Assert.AreEqual("\"" + input.ToString() + "\"", result.ToString());
        }
    }
}
